package com.hqyj.freemovie.front.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.freemovie.front.domain.MovieType;
import com.hqyj.freemovie.front.mapper.MovieTypeMapper;
import com.hqyj.freemovie.front.service.MovieTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MovieTypeServiceImpl extends ServiceImpl<MovieTypeMapper, MovieType> implements MovieTypeService {

    @Resource
    private MovieTypeMapper movieTypeMapper;
    @Override
    public List<MovieType> queryAllMovieTypes() {
        return movieTypeMapper.selectList(null);
    }

    @Transactional
    @Override
    public boolean initMovieTypes(List<MovieType> movieTypeList) throws Exception {
        try {
            for (MovieType movieType : movieTypeList) {
                movieTypeMapper.insert(movieType);
            }
            return true;
        }catch (Exception ex){
            ex.printStackTrace();
            //这句话必须写，否则不会回滚....
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
    }
}
